<template>
<div>
  <!-- <el-tabs v-model="activeName" type="card" @tab-click="handleClick"> -->
    <!-- <el-tab-pane label="资金" name="first"> -->
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="姓名">
          <el-input v-model="enamea" placeholder="姓名"></el-input>
        </el-form-item>
        <el-form-item label="分类">
          <el-select v-model="stya" placeholder="日志类型">
            <el-option label="all" value="all"></el-option>
             <el-option
              :label="style"
              :value="style"
              v-for="style in styledate"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-date-picker
          v-model="starttimea"
          type="datetime"
          placeholder="开始时间"
          align="right"
          :picker-options="pickerOptions">
        </el-date-picker> -
        <el-date-picker
          v-model="endtimea"
          type="datetime"
          placeholder="结束时间"
          align="right"
          :picker-options="pickerOptions">
        </el-date-picker>

        <el-form-item>
          <el-button type="primary" @click="lista">查询</el-button>
        </el-form-item>
      </el-form>

       <!-- 第一个资金表 -->
      <template>
        <el-table
          :data="tableDataa"
          style="width: 100%"
          :default-sort = "{prop: 'date', order: 'descending'}"
>
          <el-table-column
            label="日期"
            sortable
            width="270">
            <template slot-scope="scope">
              <span style="margin-left: 10px">{{ scope.row.date|datechange }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="ename"
            label="姓名">
          </el-table-column>
           <el-table-column
            prop="op"
            label="操作">
          </el-table-column>
          <el-table-column
            prop="ip"
            label="地址">
          </el-table-column>
          <el-table-column
            prop="yl"
            label="类型">
          </el-table-column>
        </el-table>
      </template>
    <!-- </el-tab-pane> -->

    <!-- <el-tab-pane label="客户" name="third">人员管理</el-tab-pane>
    <el-tab-pane label="其他" name="fourth">其他...</el-tab-pane> -->
  <!-- </el-tabs> -->
   <!-- 分页 -->
        <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currenta"
          :page-sizes="[5, 10, 15]"
          :page-size="5"
          layout="total, sizes, prev, pager, next, jumper"
          :total="suma">
        </el-pagination>
      </div>
  
</div>
</template>
<script>
  export default {
     filters:{
          "datechange":function(value){
              var date = new Date(value)
              var y = date.getFullYear()
              var m = date.getMonth() + 1
              m = m < 10 ? ('0' + m) : m
              var d = date.getDate()
              d = d < 10 ? ('0' + d) : d
              var h = date.getHours();
              h = h < 10 ? ('0' + h) : h
              var M = date.getMinutes() ;
              M = M < 10 ? ('0' + M) : M
              var s = date.getSeconds() ;
              s = s < 10 ? ('0' + s) : s
              return  y + '-' + m + '-' + d + " "+h+":"+M+":"+s
          }
      },
     created() {
      //资金日志展示
        this.lista();
    },
    data() {
      return {
        activeName: 'first',
        //第一个表的数据
         tableDataa: '',
        //快速时间
        pickerOptions: {
          shortcuts: [{
            text: '今天',
            onClick(picker) {
              picker.$emit('pick', new Date());
            }
          }, {
            text: '昨天',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit('pick', date);
            }
          }, {
            text: '一周前',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', date);
            }
          }]
        },
        //资金时间 - 姓名
        starttimea:'',
        endtimea:'',
        starttimea2:'',
        endtimea2:'',
        enamea:'',
        currenta:'1',
        sizea:'5',
        suma:'',
        yla:'',
        stya:'',
        styledate:'',
        total: 20,
      };
    },
    methods: {
      handleClick(tab, event) {
        console.log(tab, event);
      },

    //工资搜索
    onSubmit() {
        this.lista();
    },
     //分页
       handleSizeChange(val) {
       this.sizea = val
        this.onSubmit()
      },
      handleCurrentChange(val) {
        this.currenta = val
        this.onSubmit()
      },
    //资金展示
     lista(){
        //获取出来的标准时间  (开始时间)
          const month = this.starttimea;
          if(month == ""){ 
            const strMonth = "1900/01/00"
            this.starttimea2 = strMonth
            }
          else{
              var date = new Date(this.starttimea)
              var y = date.getFullYear()
              var m = date.getMonth() + 1
              m = m < 10 ? ('0' + m) : m
              var d = date.getDate()
              d = d < 10 ? ('0' + d) : d
               var h = date.getHours();
              h = h < 10 ? ('0' + h) : h
              var M = date.getMinutes() ;
              M = M < 10 ? ('0' + M) : M
              var s = date.getSeconds() ;
              s = s < 10 ? ('0' + s) : s
              this.starttimea2 = y + '/' + m + '/' + d + " "+h+":"+M+":"+s
        }
          // （结束时间）
          const month2 = this.endtimea;
          if(month2 == ""){
            this.endtimea2 = "2200/01/01"
          }else{
             var date = new Date(this.endtimea)
              var y = date.getFullYear()
              var m = date.getMonth() + 1
              m = m < 10 ? ('0' + m) : m
              var d = date.getDate()
              d = d < 10 ? ('0' + d) : d
               var h = date.getHours();
              h = h < 10 ? ('0' + h) : h
              var M = date.getMinutes() ;
              M = M < 10 ? ('0' + M) : M
              var s = date.getSeconds() ;
              s = s < 10 ? ('0' + s) : s
              this.endtimea2 = y + '/' + m + '/' + d+ " "+h+":"+M+":"+s
        }

        if( new Date(this.endtimea2) < new Date(this.starttimea2)){
              alert("开始日期不能小于结束日期")
              return
        }

         let self = this
          this.$axios.get("/ever-log/findAll?&starttime="+this.starttimea2+"&endtime="+this.endtimea2+"&current="+this.currenta+"&size="+this.sizea+"&yl="+this.stya+"&ename="+this.enamea
          )
        .then(res => {
          
              self.tableDataa = res.data.logList
              self.styledate = res.data.style
              self.suma = self.tableDataa[0].sum
         })
      },
    }
  };
</script>